home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 January / maximum-cd-2000-01.iso / Dreamweaver2 / data1.cab / Program_Files / Configuration / Behaviors / Actions / Timeline / Stop Timeline.js < prev   
Encoding:
JavaScript  |  1999-02-23  |  4.3 KB  |  137 lines

  1. //*************** GLOBALS VARS *****************
  2.  
  3. //******************* BEHAVIOR FUNCTION **********************
  4.  
  5. //Stops one or all timelines if they are currently playing.
  6. //Accepts the following arguments:
  7. //  tmLnName - (optional) the name of the timeline to stop (ex: Timeline1)
  8. //             if no timeline name is passed, stops all timelines
  9. //
  10. //Designed to work in conjunction with Dreamweaver's Timeline Inspector.
  11. //The Timeline Inspector creates a JS function called MM_initTimelines(),
  12. //which puts all the timeline settings in a multidimensional array, saved
  13. //into a document property called document.MM_Time.
  14. //
  15. //My function stops one or all by setting their IDs to null. Play Timeline
  16. //always checks ID after each iteration, so any outstanding timers will
  17. //stop with the next function call.
  18.  
  19. function MM_timelineStop(tmLnName) { //v1.2
  20.   //Copyright 1997 Macromedia, Inc. All rights reserved.
  21.   if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  22.   if (tmLnName == null)  //stop all
  23.     for (var i=0; i<document.MM_Time.length; i++) document.MM_Time[i].ID = null;
  24.   else document.MM_Time[tmLnName].ID = null; //stop one
  25. }
  26.  
  27.  
  28. //******************* API **********************
  29.  
  30.  
  31. //Checks for the existence of timelines.
  32. //If none exist, returns false so this Action is grayed out.
  33.  
  34. function canAcceptBehavior(){
  35.   var allScripts,i,theScript,timelineExists;
  36.  
  37.   timelineExists = false;
  38.   allScripts = getObjectTags("document","script");
  39.   for (i in allScripts) {
  40.     theScript = ""+allScripts[i];
  41.     if (theScript.indexOf("function MM_initTimelines") != -1) {
  42.       timelineExists = true;
  43.       break;
  44.   } }
  45.   return (timelineExists);
  46. }
  47.  
  48.  
  49.  
  50. //Returns a Javascript function to be inserted in HTML head with script tags.
  51.  
  52. function behaviorFunction(){
  53.   return "MM_timelineStop";
  54. }
  55.  
  56.  
  57.  
  58. //Returns fn call to insert in HTML tag <TAG... onEvent='thisFn(arg)'>
  59. //Returns one arg: the selected timeline name. If ** ALL TIMELINES **
  60. //was selected, returns no arguments.
  61.  
  62. function applyBehavior() {
  63.   menuIndex = document.theForm.menu.selectedIndex;  //get menu selection index
  64.   if (menuIndex == 0) { //stop ALL timelines, return no arg
  65.     return "MM_timelineStop()";
  66.   } else {
  67.     timelineName = document.theForm.menu.options[menuIndex].text; //gets selection
  68.     return "MM_timelineStop('"+timelineName+"')";
  69.   }
  70. }
  71.  
  72.  
  73.  
  74. //Passed the function call above, extracts the args and reloads the UI.
  75. //With arg timelineName, scans the menu for a matching item, and selects it.
  76. //If the name is not found, it gives an error msg.
  77.  
  78. function inspectBehavior(upStr){
  79.   var timelineName,menuLength,i;
  80.   var argArray = new Array;
  81.   var found = false;
  82.  
  83.   argArray = extractArgs(upStr); //get args
  84.   if (argArray.length == 2) {  //should be exactly 2 args
  85.     timelineName = argArray[1];
  86.     menuLength = document.theForm.menu.options.length;
  87.     for (var i=0; i<menuLength; i++) {  //search menu for matching timeline name
  88.       if (document.theForm.menu.options[i].text == timelineName) { //if found
  89.         document.theForm.menu.selectedIndex = i;  //make it selected
  90.         found = true;
  91.         break;
  92.       }
  93.     }
  94.     if (!found) alert(errMsg(MSG_TimelineNotFound,timelineName));
  95.   }
  96. }
  97.  
  98.  
  99.  
  100. //***************** LOCAL FUNCTIONS  ******************
  101.  
  102.  
  103. //Load the select menu with timeline names.
  104.  
  105. function initializeUI(){
  106.   var i,j,startPos,endPos,theScript;
  107.   var theName="";
  108.   var menuIndex = 0;
  109.   var allScripts = new Array;
  110.  
  111.   allScripts = getObjectTags("document","script");
  112.   for (i in allScripts) {
  113.     theScript = ""+allScripts[i];
  114.     if (theScript.indexOf("function MM_initTimelines") != -1) {
  115.       j = theScript.indexOf('].MM_Name');
  116.       while (j != -1) {
  117.         startPos = theScript.indexOf('"',++j);
  118.         endPos = theScript.indexOf('"',++startPos);
  119.         if (0 < startPos && startPos < endPos) {
  120.           if (theName=="") //first one, insert ALL option
  121.             document.theForm.menu.options[menuIndex++] = new Option("** "+MENUITEM_AllTimelines+" **");
  122.           theName = theScript.substring(startPos,endPos);
  123.           document.theForm.menu.options[menuIndex++] = new Option(theName);
  124.         }
  125.         j = theScript.indexOf('].MM_Name',j+1);
  126.       }
  127.     }
  128.   }
  129. }
  130.  
  131.  
  132.  
  133. //**************** GENERIC FUNCTIONS ****************
  134.  
  135. //function extractArgs(upStr){
  136. //function errMsg() {
  137.